home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / graphics / c3d2raw.zoo / cad3dobj.h < prev    next >
C/C++ Source or Header  |  1994-03-14  |  4KB  |  117 lines

  1. /*
  2.  * cad3d2obj - the Atari CAD-3D file format
  3.  * $Id: cad3dobj.h,v 1.1 1994/03/14 15:23:17 herborth Exp $
  4.  *
  5.  * Chris Herborth
  6.  * March 6/94
  7.  *
  8.  * Here is a handy struct or two for dealing with Atari CAD-3D 2.x files.
  9.  * See the end of this file for function prototypes!
  10.  *
  11.  * $Log: cad3dobj.h,v $
  12.  * Revision 1.1  1994/03/14  15:23:17  herborth
  13.  * Initial revision
  14.  *
  15.  */
  16.  
  17. #define CAD3D_MAGIC 0x3d02
  18.  
  19. /* The header of a CAD-3D 2.x file (*.3D2) has this structure: */
  20. typedef struct cad3d_header
  21. {
  22.     short file_id;            /* should equal 0x3d02 */
  23.     short num_objects;        /* 1-40 objs/file      */
  24.  
  25.     short light_a_flag;        /* Are the lights on? 0=off, 1=on */
  26.     short light_b_flag;
  27.     short light_c_flag;
  28.  
  29.     short light_a_bright;    /* Light brightness, scale 0-7 */
  30.     short light_b_bright;
  31.     short light_c_bright;
  32.     short ambient_bright;    /* Ambient light brightness    */
  33.  
  34.     short light_a_z;        /* Light Z position -50 to +50 */
  35.     short light_b_z;
  36.     short light_c_z;
  37.     short light_a_y;        /* Light Y position            */
  38.     short light_b_y;
  39.     short light_c_y;
  40.     short light_a_x;        /* Light X position            */
  41.     short light_b_x;
  42.     short light_c_x;
  43.  
  44.     /* The CAD-3D format docs I have are _wrong_ here!  They said these */
  45.     /* two items had 32 words, but in reality, they only have 16...     */
  46.     short obj_palette[16];
  47.     short colour_group[16];
  48.     short palette_type;        /* 0=7-shades, 1=14-shades, 2=custom        */
  49.     short wireframe_colour;    /* Wireframe line colour (1-15)             */
  50.     short outline_colour;    /* Outline line colour (0-15)               */
  51.  
  52.     char reserved[150];        /* For future expansion (ha!)               */
  53. } CAD3D_HEADER;
  54.  
  55. /* Each vertex in an object is made up of three points; this is a fixed- */
  56. /* point representation from -50.00 to 50.00.  Convert each short to a   */
  57. /* double and divide by 100.0 to get the "actual" value.                 */
  58. typedef struct cad3d_vertex
  59. {
  60.     short x;
  61.     short y;
  62.     short z;
  63. } CAD3D_VERTEX;
  64.  
  65. /* Each triangle in the file is defined by three points; each point is */
  66. /* an index into the array of vertices.                                */
  67. /* colour_edge & 0x00ff = 1-15, the face colour                        */
  68. /* if( colour_edge & 0x0100 ) - draw CA in lines-only mode             */
  69. /* if( colour_edge & 0x0200 ) - draw BC in lines-only mode             */
  70. /* if( colour_edge & 0x0400 ) - draw AB in lines-only mode             */
  71. typedef struct cad3d_triangle
  72. {
  73.     short index_a;            /* Index into the vertices array for point A */
  74.     short index_b;
  75.     short index_c;
  76.  
  77.     short colour_edge;
  78. } CAD3D_TRIANGLE;
  79.  
  80. /* Each object in the file is made up like this. */
  81. typedef struct cad3d_object
  82. {
  83.     char name[9];                    /* object name, 8 chars + NULL terminator */
  84.  
  85.     unsigned short num_vertices;    /* number of vertices in the object, <= 15000 */
  86.     CAD3D_VERTEX *vertices;            /* malloc'd array of vertices                 */
  87.  
  88.     unsigned short num_triangles;    /* number of triangles in the object, <= 30000 */
  89.     CAD3D_TRIANGLE *triangles;        /* malloc'd array of vertices */
  90. } CAD3D_OBJECT;
  91.  
  92. /* This is a "standard" RGB triad struct; we'll use this to easily convert */
  93. /* Atari ST BIOS colours into RGB ranging from 0.0 to 1.0...  If this was  */
  94. /* C++ instead of just C, you could have class rgb_alpha: public rgb_triad */
  95. typedef struct rgb_triad
  96. {
  97.     float red;
  98.     float green;
  99.     float blue;
  100. } RGB_TRIAD;
  101.  
  102. /* Function prototypes for cad3dobj.c... */
  103. short get_cad3d_header( FILE *fp, CAD3D_HEADER *head );
  104. short dump_cad3d_header( FILE *fp, const CAD3D_HEADER *head );
  105. short get_cad3d_object( FILE *fp, CAD3D_OBJECT *obj );
  106. short dump_cad3d_object( FILE *fp, const CAD3D_OBJECT *obj );
  107. short get_cad3d_vertex( FILE *fp, CAD3D_VERTEX *vert );
  108. short get_cad3d_triangle( FILE *fp, CAD3D_TRIANGLE *tri );
  109. short cad3d_triangle_colour( const CAD3D_HEADER *head,
  110.                              const CAD3D_TRIANGLE *tri );
  111. short atari2rgb( const short atari, RGB_TRIAD *rgb );
  112.  
  113. /* Damn those foolish Intel folks... */
  114. #ifdef LITTLE_ENDIAN
  115. short swap_short( const short s );
  116. #endif
  117.